package lishaole;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class java4b {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		PersonSortable2[] person=new PersonSortable2[n];
		String name;
		int age;
		for (int i = 0; i <n; i++) {
			name=sc.next();
			age=sc.nextInt();		
			person[i]=new PersonSortable2(name,age);
		}
		Arrays.sort(person,new NameComparator());
		System.out.println("NameComparator:sort");
		for (PersonSortable2 personSortable2: person) {
			System.out.println(personSortable2);
			
		}
		Arrays.sort(person,new AgeComparator());
		System.out.println("AgeComparator:sort");
		for (PersonSortable2 personSortable2 : person) {
			System.out.println(personSortable2);
			
		}
		System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
		System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
		sc.close();
	}
}
class NameComparator implements Comparator<PersonSortable2>{
	@Override
	public int compare(PersonSortable2 o1, PersonSortable2 o2) {
		// TODO Auto-generated method stub
		if(!o1.getName().equals(o2.getName())){
			if(o1.getName().compareTo(o2.getName())>0)
				return 1;
			else 
				return -1;
		}
		return 0;
	}
}
class AgeComparator implements Comparator<PersonSortable2>{
	@Override
	public int compare(PersonSortable2 o1, PersonSortable2 o2) {
		// TODO Auto-generated method stub
		if(!(o1.getAge()==o2.getAge())){
			if(o1.getAge()>o2.getAge())
				return 1;
			else 
				return -1;
		}
		return 0;
	}
}
	
class PersonSortable2 {
	private String name;
	private int age;
	
	public PersonSortable2(String name,int age){
		this.name = name;
		this.age = age;
	}
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return name+"-"+age;
	}
	/*public int compare(PersonSortable2 o) {
		int x=this.name.compareTo(o.name);
		if(x!=0)
			return x;
		
		/*if(o instanceof Person){
			o=(Person) o;
		if(!this.name.equals(((Person)o).name)){
			if(this.name.compareTo(((Person)o).name)>0)
			return 1;
			else return -1;
		}
		else if(!(this.age==(((Person)o).age))){
			if(this.age>(((Person)o).age))
				return 1;
			else return -1;
		}
		
		return 0;
	}
		return this.getAge()-o.getAge();
	}*/
}






